export type BaseQueryItemType = "must" | "should" | "must_not";

export type BaseQueryItemCondition =
  | "match"
  | "term"
  | "terms"
  | "exists"
  | "missing"
  | "wildcard"
  | "range_lt"
  | "range_lte"
  | "range_gt"
  | "range_gte";

/**
 * 基础查询
 */
export interface BaseQueryItem {
  /**
   * 唯一标识，时间戳
   */
  id: number;

  /**
   * 查询类型 <br />
   * ['must', 'should', 'must_not']
   */
  type: BaseQueryItemType;

  /**
   * 字段
   */
  field: string;

  /**
   * 条件 <br />
   * 'match', 'wildcard', 'prefix', 'range', 'fuzzy', 'query_string', 'text', 'missing'
   */
  condition: BaseQueryItemCondition;

  /**
   * 值
   */
  value: string;

  /**
   * 是否启用
   */
  isEnable: boolean;
}

export function getDefaultBaseQueryItem(): BaseQueryItem {
  return {
    id: new Date().getTime(),
    condition: "match",
    field: "",
    isEnable: true,
    type: "must",
    value: "",
  };
}
